# -*- coding: utf-8 -*- 
# 作者:飞虎
# 开发时间:2022/5/20 20:03
from PyQt5.Qt import *


class Window(QWidget):
	def __init__(self):
		super().__init__()
		self.setWindowTitle('QStackedLayout学习')
		self.resize(500, 500)
		self.setup_ui()

	def setup_ui(self):
		# 1.创建一个布局管理器对象
		sl=QStackedLayout()

		# 2.把布局对象设置给需要布局的父对象 父布局
		self.setLayout(sl)
		# 3.通过布局对象,管理布局一些子控件
		label1 = QLabel('标签1')
		label1.setStyleSheet('background-color:cyan')
		label2 = QLabel('标签2')
		label2.setStyleSheet('background-color:yellow')
		label3 = QLabel('标签3')
		label3.setStyleSheet('background-color:red')
		label4 = QLabel('标签4')
		label4.setStyleSheet('background-color:orange')

		label5 = QLabel('标签5')
		label5.setStyleSheet('background-color:pink;')
		label6 = QLabel('标签6')
		label6.setStyleSheet('background-color:blue;')
		label7 = QLabel('标签7')
		label7.setStyleSheet('background-color:cyan;')
		#
		# h_layout = QBoxLayout(QBoxLayout.BottomToTop)
		v_layout = QVBoxLayout()
		# h_layout.setDirection(QBoxLayout.RightToLeft)
		v_layout.addWidget(label5)
		v_layout.addWidget(label6)
		v_layout.addWidget(label7)

		sl.addWidget(label1)
		sl.addWidget(label2)
		sl.addWidget(label3)
		sl.addWidget(label4)

		# sl.insertWidget(1,label4)
		# sl.setCurrentIndex(2)
		# timer = QTimer(self)
		# timer.timeout.connect(lambda :sl.setCurrentIndex((sl.currentIndex()+1)%sl.count()))
		# timer.start(1000)

		# sl.setCurrentIndex(label4)

		# sl.currentChanged.connect(lambda val:print(val))
		# sl.setStackingMode(QStackedLayout.StackAll)

		# label1.hide()
		# label1.setFixedSize(100,100)
		# label2.setFixedSize(150,150)

		sl.removeWidget(label1)
		sl.removeWidget(label2)
		# print(label2.isVisible())
		# label2.show()

if __name__ == '__main__':
	import sys

	app = QApplication(sys.argv)
	window = Window()
	window.show()
	sys.exit(app.exec_())